package Threads.ThreadPool.java_threadpool;

import Threads.ThreadPool.DIY_ThreadPool.ThreadPool;

import java.util.concurrent.SynchronousQueue;

//
public class synchronousQueue_test {
    public static void main(String[] args) throws InterruptedException {
        SynchronousQueue<Integer> synchronousQueue=new SynchronousQueue<>();
        new Thread(()->{
            try {
                System.out.println("1 is put");
                synchronousQueue.put(1);
                System.out.println("done!");//只有有了拿了这个线程放的值，才会继续运行这行代码，所以put是阻塞的
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        Thread.sleep(1000);
        new Thread(()->{
            try {
                Integer take = synchronousQueue.take();
                System.out.println(take+"  is get");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
